local skill = fk.CreateSkill{
  name = "action__yifu_skill",
}

Fk:loadTranslationTable{
  ["action__yifu"] = "义父",
  ["action__yifu_skill"] = "义父",
  [":action__yifu"] = "锦囊牌<br /><b>时机</b>：出牌阶段<br /><b>目标</b>：你 <br /><b>效果</b>：令随机两名没有此效果的角色本轮随机一名获得“义父”标记，“义子”准备阶段需交给“义父”一张牌。（不可响应）",
  ["#action__yifu_skill"] = "令随机两名没有此效果的角色本轮随机一名获得“义父”标记，“义子”准备阶段需交给“义父”一张牌",
  ["@action__yifu1-round"] = "义子",
  ["@action__yifu2-round"] = "义父",
  ["#action__yifu-give-to"] = "义父：你需将一张手牌交给%src",
  ["#action__yifu1"] = "选项一：义父",
  ["#action__yifu2"] = "选项二：义子（选快了也是义父）",
}


skill:addEffect("cardskill", {
  mute = true,
  prompt = "#action__yifu_skill",
  mod_target_filter = Util.TrueFunc,
  can_use = function(self, player, card)
    return not player:isProhibited(player, card)
  end,
  on_use = function(self, room, cardUseEvent)
    cardUseEvent.disresponsiveList = table.simpleClone(Fk:currentRoom().players)
    if not cardUseEvent.tos or #cardUseEvent.tos == 0 then
      cardUseEvent.tos = { cardUseEvent.from }
    end
  end,
  on_effect = function(self, room, effect)
    local canto = table.filter(room.alive_players, function(p) return p:getMark("action__yifu1-round") == 0 end)
    if #canto < 2 then return false end
    -- local targets = table.random(canto, 2)
    -- local choices = { "#action__yifu1","#action__yifu2" }
    -- local data = { choices, choices, {0,1}, true, "义父","最快点选项的将成为“义父”", true }
    -- local req = Request:new(targets, "AskForUseActiveSkill")
    -- req.focus_text = self.name
    -- for _, p in ipairs(targets) do req:setData(p, data) end
    -- req:ask()
    -- local winners = req.winners
    -- if winners == nil then
      local to1 = table.random(table.filter(room.alive_players, function(p) return p:getMark("action__yifu1-round") == 0 end))
      local to2 = table.random(table.filter(room.alive_players, function(p) return p.id ~= to1.id and p:getMark("action__yifu1-round") == 0 end))
      room:setPlayerMark(to1,"action__yifu1-round", to2.id)
      room:setPlayerMark(to1,"@action__yifu1-round", Fk:translate(to2.general))
      room:setPlayerMark(to2,"action__yifu2-round", to1.id)
      room:setPlayerMark(to2,"@action__yifu2-round", Fk:translate(to1.general))
    -- else
    --   local to1 = winners[1]
    --   targets = table.filter(targets, function(p) return p.id ~= to1.id end)
    --   local to2 = targets[1]
    --   room:setPlayerMark(to1,"@action__yifu1-round", to2.id)
    --   room:setPlayerMark(to2,"@action__yifu2-round", to1.id)
    -- end
  end,
})

skill:addEffect(fk.EventPhaseStart, {
  mute = true,
  global = true,
  is_delay_effect = true,
  can_trigger = function(self, event, target, player, data)
    local canto = table.filter(player.room.alive_players, function(p) return p.id == player:getMark("action__yifu2-round") end)
    return target == player and player:getMark("action__yifu2-round") ~= 0 and #canto > 0 and data.phase == Player.Start
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(player:getMark("action__yifu2-round"))
    local card = room:askToCards(player, {
      min_num = 1,
      max_num = 1,
      include_equip = true,
      prompt = "#action__yifu-give-to:"..to.id,
      skill_name = self.name,
      cancelable = false,
    })
    room:obtainCard(to, card, false, fk.ReasonGive, player)
  end,
})


return skill